package com.qiuling.iot.utils;

/**
 * @Author：zhangqiang
 * @Description：
 * @Date：Created in 20:04 2020/2/11
 * @Modified By：
 */
public class CodeUtil {

    private static final String CODE_TPYE = "IOT";

    /**
     * 右补位，左对齐
     *
     * @param len    目标字符串长度
     * @param alexin 补位字符
     * @return 目标字符串
     * 以alexin 做为补位
     * @pparam oriStr  原字符串
     */
    public static String padRight(String oriStr, int len, String alexin) {
        String str = "";
        int strlen = oriStr.length();
        if (strlen < len) {
            for (int i = 0; i < len - strlen; i++) {
                str = str + alexin;
            }
        }
        str = str + oriStr;
        return str;
    }

    /**
     * @param oriStr
     * @param len
     * @param alexin
     * @return java.lang.String
     * @description 获取机构编码 IOTXXXX
     * </br>
     * @author zhangqiang
     * @date 22:02 2020/2/11
     */
    public static String getCode(String oriStr, int len, String alexin) {
        return CODE_TPYE + padRight(oriStr, len, alexin);
    }
}
